package org.budo.cmbc.direct.sdk.entity.ryb;

import java.util.ArrayList;
import java.util.List;

import org.budo.cmbc.direct.sdk.entity.AbstractCmbcDirectResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 如意宝客户收益明细查询
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
public class MELERybHisIncomeQueryResponse extends AbstractCmbcDirectResponse {
    private static final long serialVersionUID = -5969592901185115045L;

    /**
     * 总笔数
     */
    private String totalCount;

    /**
     * 明细列表
     */
    private List<MELERybIncome> incomeList;

    public MELERybHisIncomeQueryResponse(String channelJnlNo, String responseJson) {
        super(channelJnlNo, responseJson);

        JSONObject jsonObj = JSON.parseObject(responseJson);

        this.totalCount = jsonObj.getString("TotalCount");

        JSONArray jsonArr = jsonObj.getJSONArray("List");

        this.incomeList = new ArrayList<>();

        if (jsonArr != null && jsonArr.size() > 0) {
            JSONObject jsonData = (JSONObject) jsonArr.get(0);

            MELERybIncome income = new MELERybIncome();
            income.setNavDate(jsonData.getString("NavDate")).setProfit(jsonData.getString("Profit")).setProfitPerAcc(jsonData.getString("ProfitPerAcc")).setTotalShare(jsonData.getString("TotalShare")).setFundName(jsonData.getString("FundName")).setFundCode(jsonData.getString("FundCode")).setAnnualReturnBy7(jsonData.getString("AnnualReturnBy7"));

            this.incomeList.add(income);
        }
    }
}
